﻿@{
    ViewData["Title"] = "Index";
    Layout = "~/Areas/Console/Views/Shared/_Layout.cshtml";
}
@section head{
    <style type="text/css">
        .layui-table-cell {
            height: 52px;
            line-height: 52px;
        }
    </style>
    <script type="text/javascript">
        var table;
        layui.config({
            base: '../../layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['table', 'form', 'table', 'laydate', 'upload', 'element'], function () {
            var $ = layui.$
                , form = layui.form
                , admin = layui.admin
                , table = layui.table
                , laydate = layui.laydate
                , upload = layui.upload
                , element = layui.element;

            //日期时间范围
            laydate.render({
                elem: '#addtime'
                , type: 'datetime'
                , range: true
            });

            // 渲染表格
            table.render({
                elem: '#table-datalist'
                , where: { type: "0" }
                , url: '/Console/Information/GetInfomation'
                , limit: 20
                , title: '案件列表'
                , toolbar: '#table-datalist-toolbar'
                , defaultToolbar: ['filter']
                , cols: [[
                    { field: 'id', title: '编号', hide: true }
                    , {
                        field: 'number', title: '案件信息', width: 400, templet: function (res) {
                            var str = '<span  style="line-height: 25px;display: inline-block;vertical-align: middle;margin-left: 10px;"><p>部门受案号：' + res.number + '</p>'
                            str += '<p>案件名称：' + res.name + '</p>'
                            str += '</span>'
                            return str;
                        }
                    }
                    , {
                        field: 'personname', title: '嫌疑人', width: 350, templet: function (res) {
                            var str = '<span  style="line-height: 25px;display: inline-block;vertical-align: middle;margin-left: 10px;"><p>名称：' + res.personname + '</p>'
                            if (res.idcard != null)
                                str += '<p>证件号码：' + res.idcard + '</p>'
                            str += '</span>'
                            return str;
                        }
                    }
                    , { field: 'cause', title: '移送案由', width: 120 }
                    , { field: 'nature', title: '共同犯罪性质', width: 120 }
                    , { field: 'joinpersonnumber', title: '共同犯罪人数', width: 120 }
                    , { field: 'suspectedcause', title: '涉嫌案由', width: 120 }
                    , { field: 'date', title: '强制措施采取日期', width: 150 }
                    , { field: 'results', title: '审结处理结果', minWidth: 100 }
                    , { field: 'addtime', title: '添加时间', width: 200 }
                    , { field: 'updatetime', title: '最后更新时间', width: 200 }
                    , { fixed: 'right', title: '操作', width: 80, toolbar: '#table-datalist-bar' }
                ]]
                , page: { layout: ['prev', 'page', 'next', 'refresh'] }
            });

            /* 监听提交 */
            form.on('submit(search)', function (data) {
                var params = {};
                params["number"] = $("#number").val();
                params["name"] = $("#name").val();
                params["personname"] = $("#personname").val();
                params["idcard"] = $("#idcard").val();
                params["cause"] = $("#cause").val();
                params["nature"] = $("#nature").val();
                params["suspectedcause"] = $("#suspectedcause").val();
                params["results"] = $("#results").val();
                params["type"] = "0";
                table.reload('table-datalist', {
                    where: params,
                    page: { curr: 1, layout: ['prev', 'page', 'next', 'refresh'] }
                });
                return false;
            });

            //重置
            form.on('submit(reset)', function (data) {
                $('#number').val('')
                $('#name').val('')
                $('#personname').val('')
                $('#idcard').val('')
                $('#cause').val('')
                $('#nature').val('')
                $('#suspectedcause').val('')
                $('#results').val('')
                form.render()
                table.reload('table-datalist', {
                    where: { type: "0" },
                    page: { curr: 1, layout: ['prev', 'page', 'next', 'refresh'] }
                });
                return false;
            });

            //导入审查数据
            var importArrest = upload.render({
                elem: '#importArrest'//附件上传按钮ID
                , url: '/Console/Information/Import'//附件上传后台地址
                , accept: 'file'
                , multiple: 'false'
                , number: 1
                , accpetMine: '.xls,.xlsx'
                , exts: 'xls|xlsx' //只允许excel
                , choose: function (obj) {
                    showLoad();//启动动画
                }
                , done: function excel(res) {
                    closeLoad(showLoad())
                    layer.alert(res.msg)
                    table.reload('table-datalist', {
                        where: { "type": "0" },
                        page: { curr: 1, layout: ['prev', 'page', 'next', 'refresh'] }
                    });
                }
                , error: function (index, upload) {
                    console.log(index, upload)
                    layer.alert('上传失败')
                }
                , allDone: function (res) {/*全部文件上传完毕执行该方法*/ }
            });

            //导入审查数据
            var importArrestPerson = upload.render({
                elem: '#importArrestPerson'//附件上传按钮ID
                , url: '/Console/Information/Import'//附件上传后台地址
                , accept: 'file'
                , multiple: 'false'
                , number: 1
                , accpetMine: '.xls,.xlsx'
                , exts: 'xls|xlsx' //只允许excel
                , choose: function (obj) {
                    showLoad();//启动动画
                }
                , done: function excel(res) {
                    closeLoad(showLoad())
                    layer.alert(res.msg)
                    table.reload('table-datalist', {
                        where: { "type": "0" },
                        page: { curr: 1, layout: ['prev', 'page', 'next', 'refresh'] }
                    });
                }
                , error: function (index, upload) {
                    console.log(index, upload)
                    layer.alert('上传失败')
                }
                , allDone: function (res) {/*全部文件上传完毕执行该方法*/ }
            });

            function showLoad() {
                return layer.msg('数据上传中，请耐心等待...', { icon: 6, shade: [0.5, '#f5f5f5'], scrollbar: false, offset: 'auto', time: 1000000 });
            }
            //关闭动画
            function closeLoad(index) {
                layer.close(index);
            }

            //监听行工具事件
            table.on('tool(table-datalist)', function (obj) {
                var data = obj.data;
                if (obj.event === 'del') {
                    layer.confirm('确定要删除此数据吗？', function (index) {
                        $.ajax({
                            type: "POST",
                            url: "/Console/Information/Delete",
                            data: { id: data.id }, // 你的formid
                            async: true,
                            error: function (request) {
                                alert("请求超时");
                            },
                            beforeSend: function (xhr) {
                                layui.layer.load();
                            },
                            success: function (data) {
                                var item = eval(data);
                                if (item.code == 0) {
                                    layer.msg("删除成功", { icon: 1, time: 1000 }, function () {
                                        table.reload("table-datalist");
                                    });
                                } else if (item.code == 1) {
                                    layer.msg(item.msg, { icon: 2 });
                                } else {
                                    layer.msg("删除失败", { icon: 0 });
                                }
                                layer.closeAll('loading');
                            }
                        });
                    });
                }
            });

            //数据统计
            var index = 1;
            form.on('submit(caseStatistics)', function (data) {
                var layerIndex = layer.msg('数据统计中，请稍等。。。');
                index = 1;
                var _number = $("#number").val();
                var _name = $("#name").val();
                var _personname = $("#personname").val();
                var _idcard = $("#idcard").val();
                var _cause = $("#cause").val();
                var _nature = $("#nature").val();
                var _suspectedcause = $("#suspectedcause").val();
                var _results = $("#results").val();
                $.ajax({
                    type: "POST",
                    url: "/Console/Information/GetPerson",
                    data: { type: "0" },
                    async: true,
                    timeout: 60000,
                    error: function (request) {
                        layer.alert('请求失败')
                    },
                    success: function (data) {
                        layer.close(layerIndex)
                        var item = eval(data);
                        if (item.code == 0) {
                            var index = 0;
                            layer.open({
                                area: ['500px', '220px']
                                , type: 0
                                , title: '数据统计中'
                                , content: '<blockquote class="layui-elem-quote">' + item.msg + '</blockquote><div class="layui-progress layui-progress-big" lay-showPercent="true" lay-filter="progress"><div class= "layui-progress-bar layui-bg-blue" lay-percent="0%"><span class="layui-progress-text">0%</span></div></div>'
                                , success: function (layero, index) {
                                    for (var i = 0; i <= item.data.length - 1; i++) {
                                        CaseStatistics(item.data[i], 0, item.data.length);
                                    }
                                }
                            });
                        } else {
                            layer.msg(item.msg, { icon: 0 });
                        }
                    }
                });
                return false;
            });

            function CaseStatistics(id, type, total) {
                $.ajax({
                    type: "POST",
                    url: "/Console/Information/CaseStatistics",
                    data: { id: id, type: type },
                    async: true,
                    timeout: 60000,
                    error: function (request) {
                        layer.msg("请求失败", { icon: 0 });
                    },
                    success: function (data) {
                        var item = eval(data);
                        if (item.code == 0) {
                            element.progress('progress', parseInt(index / total * 100) + '%');
                            console.log(index, total, index / total * 100 + '%', parseInt(index / total * 100) + '%');
                            index++;
                        } else {
                            layer.msg(item.msg, { icon: 0 });
                        }
                    }
                });
                return false;
            }

            //清空数据
            form.on('submit(delAll)', function (data) {
                layer.confirm('确定要删除此数据吗？', function (index) {
                    $.ajax({
                        type: "POST",
                        url: "/Console/Information/DeleteAll",
                        data: { id: data.id, type: "0" }, // 你的formid
                        async: true,
                        error: function (request) {
                            alert("请求超时");
                        },
                        beforeSend: function (xhr) {
                            layui.layer.load();
                        },
                        success: function (data) {
                            var item = eval(data);
                            if (item.code == 0) {
                                layer.msg("删除成功", { icon: 1, time: 1000 }, function () {
                                    table.reload("table-datalist");
                                });
                            } else if (item.code == 1) {
                                layer.msg(item.msg, { icon: 2 });
                            } else {
                                layer.msg("删除失败", { icon: 0 });
                            }
                            layer.closeAll('loading');
                        }
                    });
                });
                return false;
            });
        });
    </script>
}
    <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
        <div class="layui-row">
            <div class="layui-col-md12">
                <div class="layui-card">
                    @*<div class="layui-card-header">条件查询</div>*@
                    <div class="layui-card-body">
                        <form class="layui-form layui-form-pane" action="" lay-filter="component-form-group">
                            <div class="layui-form-item">
                                <div class="layui-inline">
                                    <label class="layui-form-label" style="width:120px">部门受案号</label>
                                    <div class="layui-input-inline">
                                        <input type="text" id="number" name="number" value="" maxlength="25" placeholder="请填写需要查询的关键字" autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label" style="width:120px">案件名称</label>
                                    <div class="layui-input-inline">
                                        <input type="text" id="name" name="name" value="" maxlength="25" placeholder="请填写需要查询的关键字" autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label" style="width:120px">姓名/单位名称</label>
                                    <div class="layui-input-inline">
                                        <input type="text" id="personname" name="personname" value="" maxlength="25" placeholder="请填写需要查询的关键字" autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label" style="width:120px">证件号码（身份证）</label>
                                    <div class="layui-input-inline">
                                        <input type="text" id="idcard" name="idcard" value="" maxlength="25" placeholder="请填写需要查询的关键字" autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label" style="width:120px">移送案由</label>
                                    <div class="layui-input-inline">
                                        <input type="text" id="cause" name="cause" value="" maxlength="25" placeholder="请填写需要查询的关键字" autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label" style="width:120px">共同犯罪性质</label>
                                    <div class="layui-input-inline">
                                        <input type="text" id="nature" name="nature" value="" maxlength="25" placeholder="请填写需要查询的关键字" autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label" style="width:120px">罪名</label>
                                    <div class="layui-input-inline">
                                        <input type="text" id="suspectedcause" name="suspectedcause" value="" maxlength="25" placeholder="请填写需要查询的关键字" autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label" style="width:120px">处理结果</label>
                                    <div class="layui-input-inline">
                                        <input type="text" id="results" name="results" value="" maxlength="25" placeholder="请填写需要查询的关键字" autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <button class="layui-btn  layui-btn-normal search-btn" lay-submit lay-filter="search" data-type="search"><i class="layui-icon layui-icon-search"></i>搜索</button>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <input type="button" class="layui-btn layui-btn-warm" id="importArrest" value="导入审查逮捕案件信息" />
                                <input type="button" class="layui-btn layui-btn-warm" id="importArrestPerson" value="导入审查逮捕犯罪嫌疑人身份证号码信息" />
                            </div>
                        </form>
                    </div>
                </div>
                <div class="layui-card">
                    @*<div class="layui-card-header">系统用户</div>*@
                    <div class="layui-card-body">
                        <table class="layui-hide" id="table-datalist" lay-filter="table-datalist"></table>
                        <script type="text/html" id="table-datalist-toolbar">
                            <div class="layui-btn-container">
                              
                                <button class="layui-btn  layui-btn-normal search-btn" lay-submit lay-filter="caseStatistics">线索分析研判</button>
                                <button class="layui-btn  layui-btn-danger search-btn" lay-submit lay-filter="delAll">清空数据</button>
                             </div>
                        </script>
                        <script type="text/html" id="table-datalist-bar">
                            <button class="layui-btn layui-btn-danger layui-btn-sm" lay-event="del">删除</button>
                        </script>
                    </div>
                </div>
            </div>
        </div>
    </div>
